﻿<%@ Page Language="C#" AutoEventWireup="false" Inherits="My.Blog.Web.BasePage"%>
<%@ Import Namespace="My.Blog.Web.Controllers" %>
<%@ Import Namespace="My.Blog.Web" %>

<fieldset>
    <legend>添加</legend>
    <form id="FrmNewArticle" method="post" action="Ajax.aspx?Module=<%=this.Module %>&Handler=Article&Action=Add">
        <input type="hidden" name="BlogId" value="{UserId}" />
        <dl>
            <dt>CategoryId:</dt>
            <dd>
                <input type="text" class="CategoryId" readonly="readonly" />
                <input type="hidden" name="CategoryId" />
            </dd>
            
            <dt>Title:</dt>
            <dd><input type="text" name="Title" class="input-field" /></dd>
            
            <dt>Content:</dt>
            <dd>
                <div style="float:left;width:80%">
                <textarea name="Content" class="textarea-content" class="clearfix" id="ArticleContent"></textarea>
                </div>
            </dd>
            
            <dt>Summary:</dt>
            <dd><textarea name="Summary" class="textarea-summary"></textarea></dd>
            
            <dt><label>Author:</label></dt>
            <dd><input type="text" name="Author" /></dd>
            
            <dt>IsOriginal:</dt>
            <dd>
                <select name="IsOriginal"><option value="true">是</option><option value="false">否</option></select>
            </dd>
            
            <dt>
                IsPublished:</dt>
            <dd><select name="IsPublished"><option value="true">是</option><option value="false">否</option></select></dd>
            
            <dt>&nbsp;</dt>
            <dd><button>提交</button></dd>
        </dl>
    </form>
    </fieldset>
    
    <div id="afterArticleCreated"><!-- 添加后数据临时显示区域 --></div>
    
<script type="text/javascript">

$(function(){

    var frm = $("#FrmCreateArticle")
    
    // 绑定分类选择事件
    var ctrl = frm.find('.CategoryId');
    var panel = $('#categoryOptionsBase').clone();
    var valField = frm.find('[name=CategoryId]');
    
    // 设定添加文章的当前分类
    panel.find('a').each( function(i,field){
        if( field.hash.replace('#','') == '<%=Request.QueryString["CategoryId"] %>'){
            ctrl.val( $(field).text() );
            valField.val( field.hash.replace('#','') );
        }
    });
    // 如果当前分类存在,则不允许再选择分类
    if( !ctrl.val() || '' == ctrl.val() ){
        var dds = new jqDropDownSelector( ctrl,panel,function(){
            panel.find('a').click(function(){
                ctrl.val($(this).text());
                valField.val( this.hash.replace('#','') );
                dds.closePanel();
            });
        });
    }
    
    // 绑定添加事件
    frm.ajaxSubmit( function(dat,fields){
        $('body').alert(dat.response||dat.error||"");
        if( dat.response ){
            if( fields.Title ){ 
                $('#afterArticleCreated').prepend( '<p><a href="ArticleDetail.aspx?ArticleId='+dat.ArticleId+ '">' +fields.Title + '</a></p>' );
            }
        }
    });
});

</script>

<script src="_Editor/nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
	bkLib.onDomLoaded(function() { 
	    //nicEditors.allTextAreas() 
	    new nicEditor().panelInstance('ArticleContent');
	});
</script>
<!--</If:Maintain>-->
